package cn.tedu.vue_master.controller;

import cn.tedu.vue_master.pojo.user.dto.UserAddDTO;
import cn.tedu.vue_master.pojo.user.dto.UserLoginInfoDTO;
import cn.tedu.vue_master.restful.JsonResult;
import cn.tedu.vue_master.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/users")
@Api(tags = "01. 用户管理模块")
public class UserController {


    @Autowired
    private IUserService userService;

    @ApiOperation("用户登录")
    @ApiOperationSupport(order = 88)
    @PostMapping("/login")
    public JsonResult<String> login(UserLoginInfoDTO userLoginInfoDTO) {
        log.debug("开始处理【登录认证】的请求，参数：{}", userLoginInfoDTO);
        String jwt = userService.login(userLoginInfoDTO);
        userService.login(userLoginInfoDTO);
        log.debug("即将向客户端响应JWT数据：{}", jwt);
        return JsonResult.ok(jwt);
    }

    @ApiOperation("用户注册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/register")
    public JsonResult<Void> register(UserAddDTO userAddDTO) {
        log.debug("开始处理【添加用户】的请求，参数：{}", userAddDTO);
        userService.register(userAddDTO);
        return JsonResult.ok();
    }
}
